package erfgame.core.entity;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class MappedEntityTypeFactory implements EntityTypeFactory {
	
	private static final Map<Integer, EntityType> buildMap( Collection<EntityType> entityTypes ) {
		HashMap<Integer, EntityType> result = new HashMap<Integer, EntityType>( entityTypes.size() );
		for( EntityType entityType : entityTypes ) {
			result.put( entityType.getId(), entityType );
		}
		return result;
	}
	
	private Map<Integer, EntityType> entityTypes;
	
	public MappedEntityTypeFactory( Collection<EntityType> entityTypes ) {
		this( buildMap(entityTypes ) );
	}
	
	public MappedEntityTypeFactory( Map<Integer, EntityType> entityTypes ) {
		this.entityTypes = entityTypes;
	}

	public EntityType getEntityType(int id) {
		return this.entityTypes.get( id );
	}

}
